package com.eagle.ant;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.eagle.ant.activity.WeatherActivity;
import com.eagle.ant.model.Weather;
import com.eagle.ant.util.Utility;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String weatherString = prefs.getString("weather", null);
        if (weatherString != null) {
            Weather weather = Utility.handleWeatherResponse(weatherString);
            assert weather != null;

            Intent intent = new Intent(this, WeatherActivity.class);
            intent.putExtra("weather_id", weather.basic.weatherId);
            startActivity(intent);
            finish();
        }
    }
}
